
use "s2data.dta"


*PID
gen PID=pid
recode PID 1=2 2=6 3/4=4
recode PID 2=1 if pidd==1
recode PID 6=7 if pidr==1
recode PID 4=3 if pidi==1
recode PID 4=5 if pidi==2
replace PID=(PID-4)/3
recode PID -1/-.5=1 -.4/.4=2 .5/1=3, gen(PID3)
recode ideo 1/3=1 4=2 5/7=3, gen(ideo3)


*pretreatment group attitudes
rename groups_pre_1 cath_fav_pre
replace cath_fav_pre=cath_fav_pre/100

*policy attitudes. high = oppose policy
replace trans_pos=(trans_pos-4)/3
replace trans_imp=(trans_imp-1)/4
replace trans_mc=(trans_mc-1)/4
gen trans_attext=(trans_imp+trans_mc)/2

*policy attitude index
gen trans_mod=trans_pos*trans_attext

*outcomes
replace cath_values=(cath_values-1)/4
replace cath_close=(cath_close-1)/3
recode cath_fav 1=7 2=6 3=5 5=3 6=2 7=1
replace cath_fav=(cath_fav-1)/6

*outcome index
gen CathDV=(cath_values+cath_close+cath_fav)/3
alpha cath_values cath_close cath_fav, item casewise asis

gen CathTreat=.
replace CathTreat=0 if groupcond=="control"
replace CathTreat=1 if groupcond=="treatment"

rename Q129 Cath_PID
recode Cath_PID 4=1 5=2 6=3 7=4 8=5
recode cath_trans 4=1 5=2 6=3 7=4 8=5


************
* analysis *
************

*manipulation checks
reg Cath_PID CathTreat
reg cath_trans CathTreat

*main analysis
reg CathDV i.CathTreat##c.trans_mod PID cath_fav_pre
est store c1
margins, dydx(CathTreat) at(trans_mod=(-1(.2)1))
marginsplot, yline(0) recast(line) recastci(rarea) ciopts(col(gs10%30)) xtitle("Bathroom Regulation") xlab(-1 `""Strongly" "support""' -.5 " " 0 "Neither" .5 " " 1 `""Strongly" "oppose""') xsc(titlegap(2)) ytitle("Marginal Treatment Effect", size(small)) title("") subtitle("Attitudes Toward Catholics") ylab(-.2(.05).2) addplot(hist trans_mod, freq ysc(r(-.2 .2) axis(1))ylab(-.2(.1).2, axis(1)) yaxis(2) yscale(alt axis(2)) ytitle("Frequency", axis(2) size(small)) fcolor(none) bcolor(gs5%40)) legend(off) saving(s2.gph, replace)


*individual DVs
reg cath_fav i.CathTreat##c.trans_mod PID cath_fav_pre
est store c2

reg cath_close i.CathTreat##c.trans_mod PID cath_fav_pre
est store c3

reg cath_values i.CathTreat##c.trans_mod PID cath_fav_pre
est store c4


*robustness
reg CathDV i.CathTreat##c.trans_mod i.CathTreat##c.PID cath_fav_pre
est store c5

esttab c1 c5 c2 c3 c4, drop(0.CathTreat*) se(2) b(2) r2(2)



** CACE **

recode cath_trans 1/2=1 3/5=0, gen(cath_trans_di)
tab cath_trans_di CathTreat, col chi2

*favor
reg cath_trans_di CathTreat if trans_pos<0
reg CathDV CathTreat if trans_pos<0
ivregress 2sls CathDV  (cath_trans_di=CathTreat) if trans_pos<0

*oppose
reg cath_trans_di CathTreat if trans_pos>0
reg CathDV CathTreat if trans_pos>0
ivregress 2sls CathDV  (cath_trans_di=CathTreat) if trans_pos>0



*table a1. demographics
tab sex
sum age, detail
tab race
tab educ
tab PID3
tab ideo3